package org.agent.aigccore.dao.impl;

import jakarta.annotation.Resource;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.agent.aigccore.basic.enums.IotDeviceBusinessGroupStatusEnum;
import org.agent.aigccore.dao.IotDeviceBusinessGroupRepository;
import org.agent.aigccore.dao.mappers.mysql.IotDeviceBusinessGroupMapper;
import org.agent.aigccore.model.bo.IotDeviceBusinessGroupBO;
import org.agent.aigccore.model.po.IotDeviceBusinessGroupPO;
import org.springframework.stereotype.Component;

import java.util.List;

import static org.agent.aigccore.model.bo.IotDeviceBusinessGroupBO.convert;

@Slf4j
@Setter
@Component
public class IotDeviceBusinessGroupRepositoryImpl implements IotDeviceBusinessGroupRepository {

    @Resource
    private IotDeviceBusinessGroupMapper iotDeviceBusinessGroupMapper;

    @Override
    public IotDeviceBusinessGroupBO load(Long id, boolean lock) {
        if (lock) {
            return convert.formPO(iotDeviceBusinessGroupMapper.lock(id));
        }
        return convert.formPO(iotDeviceBusinessGroupMapper.load(id));
    }

    @Override
    public List<IotDeviceBusinessGroupBO> page(IotDeviceBusinessGroupStatusEnum status, String businessGroupName, int offset, int pageSize) {
        return null;
    }

    @Override
    public int insert(IotDeviceBusinessGroupBO iotDeviceBusinessGroupBO) {
        return 1;
    }

    @Override
    public int update(IotDeviceBusinessGroupBO iotDeviceBusinessGroupBO) {
        IotDeviceBusinessGroupPO po = convert.toPO(iotDeviceBusinessGroupBO);
        int num = iotDeviceBusinessGroupMapper.update(po);
        log.info("[IotDeviceBusinessGroupRepository.update] 更新成功！num={}", num);
        return num;
    }

    @Override
    public int delete(Long id) {
        int num = iotDeviceBusinessGroupMapper.delete(id);
        log.info("[IotDeviceBusinessGroupRepository.delete] 删除成功！num={}", num);
        return num;
    }
}